﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Flux_Balance_Analysis
{
    /// <summary>
    /// Logica di interazione per MetaboliteWindow.xaml
    /// </summary>
    public partial class MetaboliteWindow : Window
    {
        #region Properties
        public Metabolite Metabolite { get; private set; }
        #endregion

        public MetaboliteWindow()
        {
            InitializeComponent();
        }

        public MetaboliteWindow(Metabolite metabolite) : this()
        {
            this.Metabolite = metabolite;
            this.txtName.Text = metabolite.Name;
            chkIsExternal.IsChecked = metabolite.IsExternal;
            cmdDelete.Visibility = System.Windows.Visibility.Visible;
        }

        private void cmdCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        private void cmdConfirm_Click(object sender, RoutedEventArgs e)
        {
            // TODO : Validate metabolite name
            this.DialogResult = true;
            bool isExternal = chkIsExternal.IsChecked.HasValue ? chkIsExternal.IsChecked.Value : false;
            if (this.Metabolite == null)
            {
                this.Metabolite = new Metabolite(txtName.Text + (isExternal ? "_ext" : ""), isExternal);
            }
            else
            {
                this.Metabolite.Name = txtName.Text;
                this.Metabolite.IsExternal = isExternal;
            }
            this.Close();
        }

        private void cmdDelete_Click(object sender, RoutedEventArgs e)
        {
            this.Metabolite = null;
            this.DialogResult = true;
            this.Close();
        }
    }
}
